/*********************************************************************************
 *      Copyright:  (C) 2014 EAST
 *                  All rights reserved.
 *
 *       Filename:  test.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(07/25/2014)
 *         Author:  fulinux <fulinux@sina.com>
 *      ChangeLog:  1, Release initial version on "07/25/2014 05:15:05 PM"
 *                 
 ********************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>

static int callback(void *notused, int argc, char **argv, char **azcolname)
{
    int i;
    for(i = 0; i < argc; i++){
        printf ("%s = %s\n", azcolname[i], argv[i]?argv[i]:"NULL");
    }

    printf ("\n");
    return 0;
}


/********************************************************************************
 *  Description:
 *   Input Args:
 *  Output Args:
 * Return Value:
 ********************************************************************************/
int main (int argc, char **argv)
{
    sqlite3 *db;
    char *zerrmsg = 0;
    int rc;

    if(argc != 3){
        fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
        exit(0);
    }

    rc = sqlite3_open(argv[1], &db);
    if(rc){
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        return 1;
    }

    rc = sqlite3_exec(db, argv[2], callback, 0, &zerrmsg);
    if(rc != SQLITE_OK){
        fprintf(stderr, "SQL error: %s\n", zerrmsg);
        sqlite3_free(zerrmsg);
    }

    sqlite3_close(db);
    return 0;
} /* ----- End of main() ----- */

